找出陣列中的最大值

#C#

Posted by Phyxsius on 2023-09-16

internal class Program
{
    private static void Main(string[] args)
    {
        int[] ary = { 1, 2, 7, 3, 4};

        int max = 0;

        for(int i=0; i<ary.Length; i++)
        {
            if(i==0)
            {
                max = ary[i];
            }
            else
            {
                if (ary[i] > max)
                {
                    max = ary[i];
                }
            }
        }

        Console.WriteLine("陣列內容:");
        showArray(ary);

        Console.WriteLine("陣列最大值為:" + max);
    }

    //顯示陣列內容
    static void showArray(int[] ary)
    {
        for (int i=0; i<ary.Length; i++)
        {
            Console.Write(ary[i] + ",");
        }
        Console.WriteLine();
    }
}

#C#







Related Posts

[ 紀錄 ] 實戰練習 - 部落格 (以 Express 實作前端 + 後端)

[ 紀錄 ] 實戰練習 - 部落格 (以 Express 實作前端 + 後端)

C++ : static, extern前綴意義 (2)

C++ : static, extern前綴意義 (2)

[Day 04] 樣板模式,合成模式,狀態模式,代理模式

[Day 04] 樣板模式,合成模式,狀態模式,代理模式


Comments